#include<bits/stdc++.h>
using namespace std;
const int B=1210,N=2e5;
#include <bits/stdc++.h>
using namespace std;
namespace Fastio {
const int L = 1 << 20;
inline char gc() {
    static char buf[L], *l = buf, *r = buf;
    if (l == r)
        r = (l = buf) + fread(buf, 1, L, stdin);
    return (l == r) ? EOF : *l++;
}
char obuf[L], *p = obuf;
inline void pc(char c) {
    if (p == obuf + L)
        fwrite(obuf, 1, L, stdout), p = obuf;
    *p++ = c;
}
inline void flush() { fwrite(obuf, 1, p - obuf, stdout); }
struct Reader {
    template <typename T>
    inline Reader& operator>>(T& x) {
        x = 0;
        short f = 1;
        char c = gc();
        while (!isdigit(c)) {
            if (c == '-')
                f = -1;
            c = gc();
        }
        while (isdigit(c)) x = 10 * x + (c - '0'), c = gc();
        x *= f;
        return *this;
    }
    Reader() {}
} cin;
struct Writer {
    template <typename T>
    inline Writer& operator<<(T x) {
        if (x < 0)
            pc('-'), x = -x;
        static short tp = 0, s[40];
        do
            s[++tp] = x % 10, x /= 10;
        while (x);
        while (tp) pc(s[tp--] + '0');
        return *this;
    }
    inline Writer& operator<<(const char* s) {
        int i = 0;
        while (s[i]) pc(s[i++]);
        return *this;
    }
    inline Writer& operator<<(char c) {
        pc(c);
        return *this;
    }
    Writer() {}
    ~Writer() { flush(); }
} cout;
#define cin Fastio::cin


#define cout Fastio::cout
}
// #define int long long
int n,q;
int dfn[200005];
vector<pair<int,int> >vec[200005];
long long sum[200005];
int st[23][200005],fa[200005],siz[200005],dep[200005];
int st2[23][200005];
int tot,st3[24][200005];
int st4[24][200005];
int bid[200005],bl[N/B+20],br[N/B+20];
int maxn[N/B+20][200005],minn[N/B+20][200005];
/*
max df
min df

*/
// vector<int>vec[200005];
void dfs(int u){
	dfn[u]=++tot;siz[u]=1;
	for(int i=0;i<vec[u].size();i++){
		int v=vec[u][i].first;
		if(dfn[v])continue;
		dep[v]=dep[u]+1;
		fa[v]=u;
		sum[v]=sum[u]+vec[u][i].second;
		dfs(v);
		siz[u]+=siz[v];
	}
	
}
inline int cmp(int x,int y){
	if(dep[x]<dep[y])return x;
	return y;
}
int Lo[200005];
inline int lca(int x,int y){
	if(x==y)return x;
	int l=dfn[x],r=dfn[y];
	if(l>r)swap(l,r);
	l++;
	int L=log2(r-l+1);
	return fa[cmp(st3[L][l],st3[L][r-(1<<L)+1])];
}
inline int llca(int x,int y){
	int L=log2(y-x+1);
	return lca(st4[L][x],st4[L][y-(1<<L)+1]);
}
pair<int,int> query(int l,int r){
	int L=Lo[r-l+1];
	return {min(st2[L][l],st2[L][r-(1<<L)+1]),max(st[L][l],st[L][r-(1<<L)+1])};
}
inline long long dis(int u,int v){
	int lc=lca(u,v);
	// cout<<u<<" "<<v<<" "<<lc<<"\n";
	return sum[u]+sum[v]-sum[lc]*2;
}

inline pair<int,int>query2(int l,int r,int id){
	int qbl=bid[l],qbr=bid[r];
	long long ans1=0,ans2=0;
	if(qbl==qbr){
		// cout<<"tlh\n";
		for(int i=l;i<=r;i++){
			// cout<<i<<"\n";
			if(dfn[i]<id&&(ans2==0||dfn[i]>dfn[ans2]))ans2=i;
			if(dfn[i]>id&&(ans1==0||dfn[i]<dfn[ans1]))ans1=i;
		}
		// cout<<"re\n";
		return {ans2,ans1};
	}
	for(int i=qbl+1;i<qbr;i++){
		int ai=minn[i][id];
		if(ans1==0||dfn[ai]<dfn[ans1])ans1=ai;
		ai=maxn[i][id];
		if(ans2==0||dfn[ai]>dfn[ans2])ans2=ai;
	}
	for(int i=l;i<=br[qbl];i++){
		if(dfn[i]<id&&(ans2==0||dfn[i]>dfn[ans2]))ans2=i;
		if(dfn[i]>id&&(ans1==0||dfn[i]<dfn[ans1]))ans1=i;
	}
	for(int i=bl[qbr];i<=r;i++){
		if(dfn[i]<id&&(ans2==0||dfn[i]>dfn[ans2]))ans2=i;
		if(dfn[i]>id&&(ans1==0||dfn[i]<dfn[ans1]))ans1=i;
	}
	return {ans2,ans1};
}
inline long long solve(int l,int r,int p){
	// cout<<l<<" "<<r<<" "<<p<<"\n";
	if(l<=p&&p<=r)return 0;
	
	pair<int,int> P=query(l,r);
	// cout<<"w\n";
	int alc=llca(l,r);
	// cout<<alc<<"\n";
	if(dfn[p]<P.first&&P.second<dfn[p]+siz[p])return dis(alc,p);
	if(dfn[alc]<dfn[p]&&dfn[p]<dfn[alc]+siz[alc]){
		P=query2(l,r,dfn[p]);
		long long nu=0,de=0;
		if(P.first!=0){
			nu=lca(p,P.first);
			de=dep[nu];
		}
		if(P.second!=0){
			int u=lca(P.second,p);
			if(dep[u]>de){
				nu=u;
			}
		}
		return dis(nu,p);
	}
	return dis(alc,p);
}
/*
或者查询？【l,r】中dfn_i>p 中最小、最大的数
*/

signed main(){
	freopen("memory.in","r",stdin);
	freopen("memory.out","w",stdout);
	// ios::sync_with_stdio(0);
	// cin.tie(0),cout.tie(0);
	cin>>n>>q;
	Lo[0]=0;
	for(int i=1;i<=n;i++)Lo[i]=Lo[i>>1]+1;
	for(int i=1;i<n;i++){
		int u,v,w;
		cin>>u>>v>>w;
		vec[u].push_back({v,w});
		vec[v].push_back({u,w});
	}dep[1]=1;
	dfs(1);
	for(int i=1;i<=n;i++){
		st[0][i]=st2[0][i]=dfn[i];
		st3[0][dfn[i]]=i;
		bid[i]=(i-1)/B+1;
		vec[i].clear();
	}
		
	
	for(int i=1;i<=bid[n];i++){
		bl[i]=(i-1)*B+1,br[i]=min(i*B,n);
		for(int j=bl[i];j<=br[i];j++)maxn[i][dfn[j]]=minn[i][dfn[j]]=j;
		for(int j=1;j<=n;j++)if(maxn[i][j]==0)maxn[i][j]=maxn[i][j-1];
		for(int j=n;j>=1;j--)if(minn[i][j]==0)minn[i][j]=minn[i][j+1];
	}
	for(int i=1;i<=19;i++){
		for(int j=1;j<=n;j++){
			st[i][j]=max(st[i-1][j],st[i-1][j+(1<<(i-1))]);
			st2[i][j]=min(st2[i-1][j],st2[i-1][j+(1<<(i-1))]);
			st3[i][j]=cmp(st3[i-1][j],st3[i-1][j+(1<<(i-1))]);
		}
	}
	// for(int i=1;i<=n;i++)cout<<dfn[i]<<" ";cout<<"\n";
	
	for(int i=1;i<=n;i++)st4[0][i]=i;
	for(int i=1;i<=19;i++){
		for(int j=1;j<=n;j++)st4[i][j]=lca(st4[i-1][j],st4[i-1][j+(1<<(i-1))]);
	}
	// for(int i=0;i<=13;i++){
		// for(int j=1;j<=n;j++)cout<<st4[i][j]<<" ";
		// cout<<"\n";
	// }
	// cout<<fa[25]<<"\n";
	long long last=0;
	while(q--){
		long long l,r,p;
		cin>>p>>l>>r;
		l^=last;r^=last;p^=last;
		// cout<<l<<" "<<r<<" "<<p<<"\n";
		last=solve(l,r,p);
		cout<<last<<'\n';
	}
	return 0;
}